﻿using UnityEngine;
using System.Collections;

public class Destroyer : MonoBehaviour {

    public bool destroyOnAwake;

    public float awakeDestroyDelay;   // 设置延迟销毁的时间

    public bool findChild = false;     // 是否查询子控件

    public string namedChild;          // 子控件的名字

    private void Awake() {
        if (destroyOnAwake)
        {

            if (findChild)
            {
                Destroy(transform.Find(namedChild).gameObject);
            }
            else
            {

                Destroy(gameObject,awakeDestroyDelay);
            }

        }
    }

    void DestroyChildGameObject() {

        if (transform.Find(namedChild).gameObject != null) {
            Destroy(transform.Find(namedChild).gameObject);
        }
    }

    void DisableChildGameObject() {

        if (transform.Find(namedChild).gameObject.activeSelf == true) {
            transform.Find(namedChild).gameObject.SetActive(false);
        }
    }

    private void OnDestroyGameObject() {

        Destroy(gameObject);
    }
}
